<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>
    <th:block th:include="include :: header('纵向课题开题')" />
    <th:block th:include="include :: datetimepicker-css" />
    <th:block th:include="include :: bootstrap-fileinput-css"/>
    <th:block th:include="include :: select2-css" />
</head>
<body class="white-bg">
<div class="wrapper wrapper-content animated fadeInRight ibox-content">
    <form class="form-horizontal m" id="form-apply-add" th:object="${sciHorizontalApplyVertical}">
        <input name="id" id="ktid" th:field="*{id}" type="hidden">
        <input type="hidden" name="state" value="11">
        <h4 class="form-header h4">基本信息</h4>
        <div class="row">
            <div class="col-xs-6">
                <div class="form-group">
                    <label class="col-sm-4 control-label is-required">申请人：</label>
                    <div class="col-sm-8">
                        <input  readonly th:field="*{userName}" class="form-control" type="text" >
                    </div>
                </div>
            </div>

            <div class="col-xs-6">
                <div class="form-group">
                    <label class="col-sm-4 control-label is-required">课题类型：</label>
                    <div class="col-sm-8">
                        <select name="topType" class="form-control" th:with="type=${@dict.getType('sci_vertical_type')}" required disabled>
                            <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
                        </select>
                    </div>
                </div>
            </div>
            <div class="col-xs-6">
                <div class="form-group">
                    <label class="col-sm-4 control-label is-required">课题名称：</label>
                    <div class="col-sm-8">
                        <input readonly name="topName" th:field="*{topName}" class="form-control" type="text" required maxlength="50">
                    </div>
                </div>
            </div>
            <div class="col-xs-6">
                <div class="form-group">
                    <label class="col-sm-4 control-label is-required">课题编号：</label>
                    <div class="col-sm-8">
                        <input  th:field="*{topNumber}" class="form-control" type="text" maxlength="20">
                    </div>
                </div>
            </div>
            <div class="col-xs-6">
                <div class="form-group">
                    <label class="col-sm-4 control-label is-required">项目金额(万)：</label>
                    <div class="col-sm-8">
                        <input readonly name="amount" th:field="*{amount}" class="form-control" type="number" required step="0.0001" maxlength="9">
                    </div>
                </div>
            </div>





            <div class="col-xs-6">
                <div class="form-group">
                    <label class="col-sm-4 control-label is-required">结项日期：</label>
                    <div class="col-sm-8">
                        <div class="input-group date" >
                            <input name="validityData" autocomplete="off" th:field="*{validityData}" th:value="${#dates.format(validityData, 'yyyy-MM-dd')}" class="form-control" placeholder="yyyy-MM-dd" type="text" required>
                            <span class="input-group-addon"><i class="fa fa-calendar"></i></span>
                        </div>
                    </div>
                </div>
            </div>

            <div class="col-xs-6">
                <div class="form-group">
                    <label class="col-sm-4 control-label is-required">主持人：</label>
                    <div class="col-sm-8">
                        <select name="firstPersonId" class="form-control m-b" disabled >
                            <option th:each="user : ${sysUsers}" th:text="${user.userName}" th:value="${user.userId}" th:selected="${ #strings.toString(user.userId) == sciHorizontalApplyVertical.firstPersonId}" readonly></option>
                        </select>
                    </div>
                </div>
            </div>

            <div class="col-xs-6">
                <div class="form-group">
                    <label class="col-sm-4 control-label is-required">成员1：</label>
                    <div class="col-sm-8">
                        <!--                        <input name="secondPersonTask" th:field="*{secondPersonTask}" class="form-control" type="text" required>-->
                        <select name="secondPersonId" class="form-control m-b" disabled>
                            <option th:each="user : ${sysUsers}" th:text="${user.userName}" th:value="${user.userId}" th:selected="${ #strings.toString(user.userId) == sciHorizontalApplyVertical.secondPersonId}" readonly></option>
                        </select>
                    </div>
                </div>
            </div>

            <div class="col-xs-6">
                <div class="form-group">
                    <label class="col-sm-4 control-label is-required">成员2：</label>
                    <div class="col-sm-8">
                        <!--                        <input name="thirdPersonId" th:field="*{thirdPersonId}" class="form-control" type="text" required>-->
                        <select name="thirdPersonId" class="form-control m-b" disabled>
                            <option th:each="user : ${sysUsers}" th:text="${user.userName}" th:value="${user.userId}" th:selected="${ #strings.toString(user.userId) == sciHorizontalApplyVertical.thirdPersonId}" readonly ></option>
                        </select>
                    </div>
                </div>
            </div>

            <div class="col-xs-6">
                <div class="form-group">
                    <label class="col-sm-4 control-label is-required">成员3：</label>
                    <div class="col-sm-8">
                        <!--                        <input name="fourthPersonId" th:field="*{fourthPersonId}" class="form-control" type="text" required>-->
                        <select name="fourthPersonId" class="form-control m-b" disabled>
                            <option th:each="user : ${sysUsers}" th:text="${user.userName}" th:value="${user.userId}" th:selected="${ #strings.toString(user.userId) == sciHorizontalApplyVertical.fourthPersonId}" readonly ></option>
                        </select>
                    </div>
                </div>
            </div>

            <!-- 其他成员（第5位及以后）：只读展示 -->
            <div class="col-xs-12" th:if="${extraMembers != null}">
                <div class="form-group">
                    <label class="col-sm-2 control-label">其他成员：</label>
                    <div class="col-sm-10">
                        <div id="memberContainer" class="row">
                            <div class="col-xs-3 m-b-xs" th:each="mid : ${extraMembers}">
                                <select class="form-control m-b" disabled>
                                    <option th:each="user : ${sysUsers}" th:text="${user.userName}" th:value="${user.userId}" th:selected="${ #strings.toString(user.userId) == mid }"></option>
                                </select>
                            </div>
                        </div>
                    </div>
                </div>
            </div>

            <div class="col-xs-4">
                <div class="form-group">
                    <label class="col-sm-4 control-label is-required">开题文件：</label>
                    <div class="col-sm-8">
                        <input type="hidden" name="openfile">
                        <div class="file-loading">
                            <input class="form-control file-upload1" id="openfile" name="file" type="file">
                        </div>
                    </div>
                </div>
            </div>
            <div class="col-xs-4">
                <div class="form-group">
                    <label class="col-sm-4 control-label is-required">中期文件：</label>
                    <div class="col-sm-8">
                        <input type="hidden" name="midfile">
                        <div class="file-loading">
                            <input class="form-control file-upload2" id="midfile" name="file" type="file">
                        </div>
                    </div>
                </div>
            </div>
            <div class="col-xs-4">
                <div class="form-group">
                    <label class="col-sm-4 control-label is-required">结项文件：</label>
                    <div class="col-sm-8">
                        <input type="hidden" name="overfile">
                        <div class="file-loading">
                            <input class="form-control file-upload3" id="overfile" name="file" type="file">
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </form>
</div>
<div class="row">
    <div class="col-sm-offset-5 col-sm-10">
        <button type="button" class="btn btn-sm btn-primary" onclick="submitHandler()">  </i>保 存</button>&nbsp;
        <button type="button" class="btn btn-sm btn-danger" onclick="closeItem()"> 关 闭 </button>
    </div>
</div>
<th:block th:include="include :: footer" />
<th:block th:include="include :: datetimepicker-js" />
<th:block th:include="include :: bootstrap-fileinput-js"/>
<th:block th:include="include :: datetimepicker-js" />
<th:block th:include="include :: select2-js" />

<script th:inline="javascript">
    var prefix = ctx + "system/apply_vertical"
    $("#form-apply-add").validate({
        focusCleanup: true
    });

    $("input[name='validityData']").datetimepicker({
        format: "yyyy-mm-dd",
        minView: "month",
        autoclose: true
    });

    window.ktidValue = document.getElementById("ktid").value;
    $("#applyVertivalId").val(window.ktidValue);

    $("input[name='amount']").on('input', function() {
        var value = $(this).val();
        // 限制整数部分不超过9位
        if (value) {
            var numericValue = parseFloat(value);
            // 限制整数部分长度
            if (value.indexOf('.') !== -1) {
                var parts = value.split('.');
                if (parts[0].length > 9) {
                    $(this).val(parts[0].substring(0, 9) + (parts[1] ? '.' + parts[1] : ''));
                }
            } else {
                if (value.length > 9) {
                    $(this).val(value.substring(0, 9));
                }
            }
            // 限制小数点后只能输入四位
            if (value.indexOf('.') !== -1) {
                var parts = value.split('.');
                if (parts[1] && parts[1].length > 4) {
                    $(this).val(parts[0] + '.' + parts[1].substring(0, 4));
                }
            }
            // 限制最大值
            if (numericValue > 999999999) {
                $(this).val("000000000");
            }
        }
    });

    function submitHandler() {
        if ($.validate.form()) {
            if($("input[name='openfile']").val()=="")
                return $.modal.alertError("请上传文件1");
            if($("input[name='midfile']").val()=="")
                return $.modal.alertError("请上传文件2");
            if($("input[name='overfile']").val()=="")
                return $.modal.alertError("请上传文件3");
            $.operate.saveTab(prefix + "/overadd", $('#form-apply-add').serialize());
        }

    }
    $(".file-upload1").fileinput({
        uploadUrl: ctx + 'common/upload/zxkt',
        initialPreviewAsData: true,
        maxFileCount: 1,
        maxFileSize: 51200,
        autoReplace: true,
        allowedFileExtensions: ["pdf"],
        slugCallback: function(filename) {
            if ($("input[name='topName']").val()===""){
                $(".file-uploadb").fileinput('clear');
                $.modal.alertError("请先输入课题名称");
                return false;
            }
            // 自定义文件名生成规则
            fileExtension = filename.split('.').pop();
            const year = new Date().getFullYear();
            const newName = year +"-"+ $("input[name='topName']").val() +"-"+ "开题文件"+ "." + fileExtension;
            return newName;
        },
    }).on('fileuploaded', function (event, data, previewId, index) {
        $("input[name='" + event.currentTarget.id + "']").val(data.response.url)
    }).on('fileremoved', function (event, id, index) {
        $("input[name='" + event.currentTarget.id + "']").val('')
    })
    $(".file-upload2").fileinput({
        uploadUrl: ctx + 'common/upload/zxkt',
        initialPreviewAsData: true,
        maxFileCount: 1,
        maxFileSize: 51200,
        autoReplace: true,
        allowedFileExtensions: ["pdf"],
        slugCallback: function(filename) {
            if ($("input[name='topName']").val()===""){
                $(".file-uploadb").fileinput('clear');
                $.modal.alertError("请先输入课题名称");
                return false;
            }
            // 自定义文件名生成规则
            fileExtension = filename.split('.').pop();
            const year = new Date().getFullYear();
            const newName = year +"-"+ $("input[name='topName']").val() +"-"+ "中期文件"+ "." + fileExtension;
            return newName;
        },
    }).on('fileuploaded', function (event, data, previewId, index) {
        $("input[name='" + event.currentTarget.id + "']").val(data.response.url)
    }).on('fileremoved', function (event, id, index) {
        $("input[name='" + event.currentTarget.id + "']").val('')
    })
    $(".file-upload3").fileinput({
        uploadUrl: ctx + 'common/upload/zxkt',
        initialPreviewAsData: true,
        maxFileCount: 1,
        maxFileSize: 51200,
        autoReplace: true,
        allowedFileExtensions: ["pdf"],
        slugCallback: function(filename) {
            if ($("input[name='topName']").val()===""){
                $(".file-uploadb").fileinput('clear');
                $.modal.alertError("请先输入课题名称");
                return false;
            }
            // 自定义文件名生成规则
            fileExtension = filename.split('.').pop();
            const year = new Date().getFullYear();
            const newName = year +"-"+ $("input[name='topName']").val() +"-"+ "结项文件"+ "." + fileExtension;
            return newName;
        },
    }).on('fileuploaded', function (event, data, previewId, index) {
        $("input[name='" + event.currentTarget.id + "']").val(data.response.url)
    }).on('fileremoved', function (event, id, index) {
        $("input[name='" + event.currentTarget.id + "']").val('')
    })
</script>
</body>
</html>